package com.leetcode.linkedList;

import com.leetcode.basic.ListNode;

/**
 * @author Dennis Li
 * @date 2020/6/11 21:35
 */
public class RevomeDuplicateNode_83 {

    // 对子结构产生影响。那么可以使用递归
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null || head.next == null) return head;
        // 修改链表
        head.next = deleteDuplicates(head.next);
        // 返回头部结点
        return head.val == head.next.val ? head.next : head;
    }

    static class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            if (head == null || head.next == null) return head;
            head.next = deleteDuplicates(head.next);
            return head.val != head.next.val ? head : head.next;
        }
    }

}

